package http_servlet_response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Creared with IntelliJ IDEA.
 * Description:自动刷新页面
 * User:yxd
 * Date:2022-05-31
 * Time:20:59
 */
@WebServlet("/autoRefresh")
public class AutoRefresh extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //通过设置setHeader就可以实现自动刷新
        //第一参数就是刷新,第二个参数表示每个一秒刷新一次
        resp.setHeader("Refresh","1");

        //保证不会乱码
        resp.setContentType("text/html;charset=utf8");
        //为了更明显的看出来页面有刷新的痕迹,这里就设置一个时间戳
        resp.getWriter().write("当前时间戳:" + System.currentTimeMillis());
    }
}
